unit MainForm;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  IfxTable, Db, IfxCustomDataset, IfxQuery, IfxConnection, StdCtrls, Grids,
  DBGrids, IfxMonitor, IfxVisualMonitor, LXDataSetImpl, LXUpdateSQL,
  IfxUpdateSQL, DBCtrls, IfxFieldTypes, DBClient, IfxSQL, Provider, DBTables,
  IfxDataSet, IfxDecimal, IfxConvert, IfxNativeFields, IfxLob, Ifx, IfxIntf;

type
  TForm1 = class(TForm)
    IfxConnection1: TIfxConnection;
    IfxQuery1: TIfxQuery;
    DBGrid1: TDBGrid;
    DataSource1: TDataSource;
    Reopen: TButton;
    IfxVisualMonitor1: TIfxVisualMonitor;
    DBMemo1: TDBMemo;
    IfxFieldTypes1: TIfxFieldTypes;
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    Button4: TButton;
    Button5: TButton;
    procedure FormCreate(Sender: TObject);
    procedure ReopenClick(Sender: TObject);
    procedure DBGrid1ColEnter(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure Button4Click(Sender: TObject);
    procedure Button5Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
    function ActiveDataSet: TDataSet;
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

{ TForm1 }

function TForm1.ActiveDataSet: TDataSet;
begin
  Result := IfxQuery1;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  DataSource1.DataSet := ActiveDataSet;
end;

procedure TForm1.ReopenClick(Sender: TObject);
begin
  ActiveDataSet.Active := not ActiveDataSet.Active;
  if ActiveDataSet.Active then
    DBGrid1ColEnter(DBGrid1);
end;

procedure TForm1.DBGrid1ColEnter(Sender: TObject);
begin
  DBMemo1.DataField := DBGrid1.SelectedField.FieldName;
end;

procedure TForm1.Button1Click(Sender: TObject);
var
  I: Integer;
  Params: TIfxParams;
begin
  Params := TIfxParams.Create;
  try
    //!!!Params.LobFactory := TIfxLobFactory.Create(IfxConnection1);
    Params.Reset(2);
    for I := 0 to 1000 do
    begin
      Params[0].LoadFromFile('C:\Program Files\Borland\Delphi6\Source\Vcl\dblookup.pas', ftOraBlob);
      Params[1].LoadFromFile('C:\Program Files\Borland\Delphi6\Source\Vcl\ExtActns.pas', ftOraClob);
      IfxConnection1.Execute('insert into regress (c_blob, c_clob) values (?, ?)', Params);
    end;
  finally
    Params.Free;
  end;
end;

procedure TForm1.Button2Click(Sender: TObject);
var
  S: TStream;
  FS: TFileStream;
begin
  FS := TFileStream.Create('D:\_image_usage_stats.vbs', fmOpenRead);
  try
    ActiveDataSet.Edit;
    S := ActiveDataSet.CreateBlobStream(DBGrid1.SelectedField, bmWrite);
    try
      S.CopyFrom(FS, 0);
    finally
      S.Free;
      ActiveDataSet.Post;
    end;
  finally
    FS.Free;
  end;
end;

procedure TForm1.Button3Click(Sender: TObject);
begin
  DBGrid1.SelectedField.DataSet.Edit;
  DBGrid1.SelectedField.Clear;
end;

procedure TForm1.Button4Click(Sender: TObject);
begin
  IfxConnection1.Execute('insert into regress (c_char) values (''asd'')');
  ShowMessage(IntToStr(IfxConnection1.LastInsertedSerial));
  ShowMessage(IntToStr(IfxConnection1.LastInsertedRowID));
  ShowMessage(Int8ToString(IfxConnection1.LastInsertedSerial8));
end;

procedure TForm1.Button5Click(Sender: TObject);
begin
  IfxQuery1.ApplyUpdates;
end;

end.
